<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.lmpop.trade.ti_discountpolicy.Ti_discountpolicyInfo"%> 
<%@page import="com.lmpop.trade.ts_custclass.*" %>
<%@page import="com.lmpop.trade.ti_voucher.*" %>
<%@page import="com.lmpop.trade.ti_gift.*" %>
<%@ page import="com.lmpop.trade.ti_attach.Ti_attachInfo" %>
<%@page import="com.lmpop.trade.ts_category.Ts_categoryInfo"%>
<%@ page import="com.lmpop.trade.ti_attach.Ti_attachInfo" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	 
		String discount_id="",s_cust_id="",p_type="";
  	if(request.getParameter("model_id")!=null) discount_id = request.getParameter("model_id");
  	if(request.getParameter("cust_id")!=null && !request.getParameter("cust_id").equals("")){		
			s_cust_id = request.getParameter("cust_id"); 		
		}
		if(request.getParameter("t")!=null && !request.getParameter("t").equals("")){		
			p_type = request.getParameter("t"); 		
		}
		Ti_attachInfo  ti_attachInfo = new Ti_attachInfo(); 
  	Ti_discountpolicyInfo ti_discountpolicyInfo = new Ti_discountpolicyInfo();
  	Map dpinfoMap = new Hashtable();
		dpinfoMap.put("discount_id",discount_id);
		dpinfoMap.put("offer_type",p_type);
  	
  	List list = ti_discountpolicyInfo.getListByPage(dpinfoMap,0,100);
  	
  	Hashtable map = new Hashtable();
  	if(list!=null && list.size()>0) map = (Hashtable)list.get(0);
  	
  	String good_offer="",class_attr="",member_level="",offer_type="",spending="",number="",discount="",ship_offer="",voucher_type="",voucher_num="",send_a_few="",gift_ids="",order_amount="",start_time="",end_time="",rsrv_str1="",rsrv_str2="",rsrv_str3="",in_date="",user_id="";
  	if(map.get("member_level")!=null) member_level = map.get("member_level").toString();
  	if(map.get("class_attr")!=null) class_attr = map.get("class_attr").toString();
  	if(map.get("offer_type")!=null) offer_type = map.get("offer_type").toString();
  	if(map.get("spending")!=null) spending = map.get("spending").toString();
  	if(map.get("number")!=null) number = map.get("number").toString();
  	if(map.get("discount")!=null) discount = map.get("discount").toString();
  	if(map.get("ship_offer")!=null) ship_offer = map.get("ship_offer").toString();
  	if(map.get("voucher_type")!=null) voucher_type = map.get("voucher_type").toString();
  	if(map.get("voucher_num")!=null) voucher_num = map.get("voucher_num").toString();
  	if(map.get("send_a_few")!=null) send_a_few = map.get("send_a_few").toString();
  	if(map.get("gift_ids")!=null) gift_ids = map.get("gift_ids").toString();
  	if(map.get("order_amount")!=null) order_amount = map.get("order_amount").toString();
  	if(map.get("start_time")!=null) start_time = map.get("start_time").toString();
  	if(map.get("end_time")!=null) end_time = map.get("end_time").toString();
  	if(start_time.length()>10)start_time=start_time.substring(0,10);
  	if(end_time.length()>10)end_time=end_time.substring(0,10);
  	if(map.get("in_date")!=null) in_date = map.get("in_date").toString();
  	if(map.get("user_id")!=null) user_id = map.get("user_id").toString();
  	if(map.get("good_offer")!=null) good_offer = map.get("good_offer").toString();
  	p_type = offer_type;
  	 
		 
		
		String catAttr[] = class_attr.split("\\|");
	  String cat_names ="";  
	  if(!class_attr.equals(""))
	  {
	      String catIds[] =	class_attr.split("\\|");	
	       Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
	       Map catMap = ts_categoryInfo.getCatClassMap("2");
	      for(String catId:catIds)
	      {
	         if(catMap!=null)
	         {
	             if(catMap.get(catId)!=null)
	             {
	              cat_names +=catMap.get(catId).toString()+"  ";                 
	             }                  
	         
	         }                 
	      }		    
		 }
%>

<html>
  <head>
    <title>添加优惠策略设置</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="index.js"></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_discountpolicyInfo.js'></script>  
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_giftInfo.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_PaymentRulesInfo.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ts_categoryInfo.js'></script> 
	<script type="text/javascript" src="/program/admin/goods/s_classify.js"></script>
	<script language="javascript" type="text/javascript" src="/program/plugins/calendar/WdatePicker.js"></script>
</head>

<body>
	<h1>添加优惠策略设置</h1>
	
	<form action="/doTradeReg.do" method="post" name="updateForm">
	
	
	<table width="100%" cellpadding="0" cellspacing="1" border="0" class="listtab">		
		<tr>
			<td align="right" width="30%">
				 <p style="font-size:16px;font-weight:bold;color:red">优惠条件</p>
			</td>
			<td></td>
		</tr>
		<tr style="display:<% if (p_type.equals("1") || p_type.equals("3") || p_type.equals("4")) out.print(""); else out.print("none");%>;">
			<td align="right" width="30%">
				<% if (p_type.equals("4")) out.print("一年内");%>订单商品总金额满：
			</td>
			<td><input name="spending" id="spending" size="15" maxlength="10"  value="<%=spending%>" type="text" onKeyUp="if(isNaN(value))this.value=''"/> （元）</td>
		</tr>
		
		<tr style="display:<% if (p_type.equals("2")) out.print(""); else out.print("none");%>;">
			<td align="right" width="30%">
				订单商品总数量满：
			</td>
			<td><input name="number" id="number" size="15" maxlength="10" value="<%=number%>" type="text" onKeyUp="if(isNaN(value))this.value=''"/> （销售计量单位）</td>
		</tr>
		<tr>
			<td align="right" width="30%">
				 <p style="font-size:16px;font-weight:bold;color:red">优惠策略</p>
			</td>
			<td><% if (p_type.equals("5")) out.print("尾货清仓");%></td>
		</tr>
		
		<tr style="display:<% if (p_type.equals("3") || p_type.equals("4")) out.print(""); else out.print("none");%>;">
			<td align="right" width="30%">
				<% if (p_type.equals("4")) out.print("累计返利"); else out.print("打折率");%>
			</td>
			<td><input name="discount" id="discount" size="15" maxlength="10" type="text" value="<%=discount%>"  onKeyUp="if(isNaN(value))this.value=''"/>% （例：90即9折）</td>
		</tr>
		
		<tr style="display:<% if (p_type.equals("a")) out.print(""); else out.print("none");%>;">
			<td align="right" width="30%">
				运费优惠：
			</td>
			<td><input name="ship_offer" id="ship_offer" size="15" maxlength="10" value="<%=ship_offer%>" type="text" onKeyUp="if(isNaN(value))this.value=''"/>元</td>
		</tr>
		
		<tr style="display:<% if (p_type.equals("2")) out.print(""); else out.print("none");%>;">
			<td align="right" width="30%">
				送几个：
			</td>
			<td><input name="send_a_few" id="send_a_few" size="15" maxlength="10" value="<%=send_a_few%>" type="text" onKeyUp="if(isNaN(value))this.value=''" />（相同的订单商品）</td>
		</tr>

		 
		
		<tr style="display:<% if (p_type.equals("1")) out.print(""); else out.print("none");%>;">
			<td align="right" width="30%">
				赠送礼品：
			</td>
			<td>
				<ul style="width:100%;margin:0;">
					<%
						Ti_giftInfo giftinfo = new Ti_giftInfo(); 
						Map giftinfoMap = new Hashtable();
						giftinfoMap.put("cust_id",s_cust_id);
					  List giftlist = giftinfo.getListByPage(giftinfoMap,0,1000);
						int listsize = 0;
						if (giftlist!=null && giftlist.size()>0)
						{
							listsize = giftlist.size();
							Hashtable giftmap = new Hashtable();
							for(int i=0;i<giftlist.size();i++)
							{
								String gift_id="",gift_name="",img_path="";
								giftmap = (Hashtable)giftlist.get(i);
								if(giftmap.get("gift_id")!=null) gift_id = giftmap.get("gift_id").toString(); 
								if(giftmap.get("gift_name")!=null) gift_name = giftmap.get("gift_name").toString(); 
								img_path =  ti_attachInfo.getFilePathByAttachrootid(gift_id);            
								if(img_path.equals("")) img_path ="/program/admin/images/cpwu.gif";          
					%>
						<li style="width:30%;float:left;padding-left:10px">
							<input type="checkbox" name="checkone<%=i%>" id="checkone<%=i%>" value="<%=gift_id %>" <% if (gift_ids.indexOf(gift_id)>-1) out.print("checked");%>/>
							<img src="<%=img_path%>" style="width:100;height:100;border:5px solid #999;"><br>
							<span style="font-size:14px;font-weight:bold;color:<% if (gift_ids.indexOf(gift_id)>-1) out.print("red"); else out.print("blue");%>"><%=gift_name%></span>
						</li>
					<%  
							}
						}
					%>
				</ul>
			</td>
		</tr>		
		<tr>
			<td align="right" width="30%">
				 <p style="font-size:16px;font-weight:bold;color:red">有效时间</p>
			</td>
			<td></td>
		</tr>
		<tr>
			<td align="right" width="30%">
				开始时间：<font color="red">*</font>
			</td>
			<td>
				<input name="start_time" id="start_time" value="<%=start_time %>" size="20" maxlength="20" type="text"
				 onfocus="WdatePicker({readOnly:true})" />
			</td>
		</tr>
		
		<tr>
			<td align="right" width="30%">
				结束时间：<font color="red">*</font>
			</td>
			<td><input name="end_time" id="end_time" size="20" maxlength="20" value="<%=end_time %>"  type="text" onfocus="WdatePicker({readOnly:true})" /></td>
		</tr>
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td align="center">
				<input type="hidden" name="bpm_id" value="2875" />
				<input name="discount_id" id="discount_id" type="hidden" value="<%=discount_id%>"/>
  			<input name="offer_type" id="offer_type" type="hidden" value="<%=p_type%>"/>
				<input type="hidden" name="class_attr" id="class_attr" value="" />
				<input type="hidden" name="listsize" id="listsize" value="<%=listsize %>" />
				<input type="hidden" name="gift_ids" id="gift_ids" value="" />
				<input name="user_id" id="user_id" value="<%=user_id %>" type="hidden" />
				<input type="button" class="buttoncss" name="tradeSub" value="提交" onclick="return checkSub('updateForm');"/>&nbsp;&nbsp;
				<input type="button" class="buttoncss" name="tradeRut" value="返回" onclick="window.history.go(-1);"/>
			</td>
		</tr>
	</table>
	</form>
</body>

</html>
